package com.xnck.maventest.service;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xnck.maventest.entity.Account;
import com.xnck.maventest.entity.User;

@Service
public class RootService {

	@Autowired
	private UserService userService;
	
	@Autowired
	private AccountService accountService;
	
	public User getUserById(String userId){
		return userService.getUserById(userId);
	}
	
	public void createUser(String userId) throws Exception{
		User user = new User();
		user.setUserId(userId);
		user.setUserName("张三");
		
		Account account = new Account();
		account.setId(UUID.randomUUID().toString());
		account.setAccount("zhangsan");
		account.setUserId(user.getUserId());
		
		userService.addUser(user);
		if (userId.equals("test01")) {
			throw new Exception("人为制造的错误");
		}
		accountService.addAccount(account);
	}
}
